import { Button } from "../../../fl/controls/Button";
import { IToolTipItem } from "../manager/IToolTipItem";
import { IFrUI } from "../core/IFrUI";
import { ImageInfo } from "../../gengine/resource/info/ImageInfo";
import { LoaderManager } from "../../gengine/resource/LoaderManager";
import { Global } from "../../gengine/global/Global";
import { ToolTipsManager } from "../manager/ToolTipsManager";
import { ObjEventListerTool } from "../utils/ObjEventListerTool";
import { IDispose } from "../../gengine/core/IDispose";
import { UICompomentPool } from "../utils/UICompomentPool";
type int = number;
//class GImageButton
    
    export  class GImageButton extends Button implements IToolTipItem, IFrUI
    {
        constructor()
        {
            
            super();this.buttonMode = true;
            this.useHandCursor = true;
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.judgeToolTip);
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.judgeToolTip);
            return;
        }

        public set overSkin(arg1: string)
        {
            this.setSkin("overSkin", arg1);
            return;
        }

        public set upSkin(arg1: string)
        {
            this.setSkin("upSkin", arg1);
            return;
        }

        public set disabledSkin(arg1: string)
        {
            this.setSkin("disabledSkin", arg1);
            return;
        }

        public set downSkin(arg1: string)
        {
            this.setSkin("downSkin", arg1);
            return;
        }

        public setSkin(arg1: string, arg2: string): void
        {
            var type: string;
            var url: string;
            var onLoadedSkin: Function;

            var loc1;
            onLoadedSkin = null;
            type = arg1;
            url = arg2;
            onLoadedSkin = (arg1: ImageInfo): void
            {
                GImageButton._bitmapDataMap[url] = arg1.bitmapData;
                setStyle(type, new Object /* flash.display.Bitmap */(arg1.bitmapData));
                return;
            }
            if (url in GImageButton._bitmapDataMap) 
            {
                setStyle(type, new Object /* flash.display.Bitmap */(GImageButton._bitmapDataMap[url] as Object /* flash.display.BitmapData */));
            }
            else 
            {
                LoaderManager.instance.load(url, onLoadedSkin);
            }
            return;
        }

        public get toolTipData()
        {
            return this._toolTipData;
        }

        public set toolTipData(arg1)
        {
            this._toolTipData = arg1;
            this.judgeToolTip();
            return;
        }

        protected judgeToolTip(arg1: Object /* flash.events.Event */=null): void
        {
            if (arg1 && arg1.type == flash.events.Event.ADDED_TO_STAGE && this.toolTipData || !arg1 && this.toolTipData && Global.stage.contains(this)) 
            {
                ToolTipsManager.register(this);
            }
            else 
            {
                ToolTipsManager.unregister(this);
            }
            return;
        }

        public configEventListener(arg1: string, arg2: Function, arg3: Boolean=false, arg4: int=0, arg5: Boolean=false): void
        {
            ObjEventListerTool.addObjEvent(this, arg1, arg2, arg3);
            addEventListener(arg1, arg2, arg3, arg4, arg5);
            return;
        }

        public /* override */ removeEventListener(arg1: string, arg2: Function, arg3: Boolean=false): void
        {
            ObjEventListerTool.removeObjEvent(this, arg1, arg2, arg3);
            super.removeEventListener(arg1, arg2, arg3);
            return;
        }

        public dispose(arg1: Boolean=true): void
        {
            var loc2=0;
            var loc3=null;
            clearStyle("overSkin");
            clearStyle("upSkin");
            clearStyle("disabledSkin");
            clearStyle("downSkin");
            ObjEventListerTool.delObjEvent(this);
            var loc1=this.numChildren;
            --loc2;
            while (loc2 >= 0) 
            {
                if ((loc3 = this.getChildAt(loc2)) is IDispose) 
                {
                    this.removeChild(loc3);
                    (loc3 as IFrUI).dispose(arg1);
                }
                --loc2;
            }
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            if (arg1) 
            {
                UICompomentPool.disposeUICompoment(this);
            }
            return;
        }

        private /* var */_overSkinUrl: string;

        private /* var */_upSkinUrl: string;

        private /* var */_downSkinUrl: string;

        private /* var */_disabledSkinUrl: string;

        protected /* var */_toolTipData;

        private static /* var */_bitmapDataMap: Map<any, any> /* flash.utils.Dictionary */;
    }

            GImageButton._bitmapDataMap = new Map<any, any> /* flash.utils.Dictionary */();
        